package main

import (
	"fmt"
	"strconv"
	"time"

	"gitee.com/wulalade/hwpack/tts"
	"gitee.com/wulalade/hwpack/utils"
)

func main() {
	tipTime := time.Now()
	path := utils.GetWorkPath() + "/"
	workDir := path + "../../etc/res"
	workDir2JetPath := path + "../../etc/res/tts/"
	fmt.Println("workDir : ", workDir)
	fmt.Println("workDir2JetPath : ", workDir2JetPath)
	params := fmt.Sprintf("engine_type = local, voice_name = xiaoyan, text_encoding = UTF8, tts_res_path = fo|%sxiaoyan.jet;fo|%scommon.jet, sample_rate= 16000, speed = 50, volume = 50, pitch = 50, rdn = 0",
		workDir2JetPath, workDir2JetPath)
	err := tts.Login(fmt.Sprintf("appid = 603f4287, work_dir = %s", workDir))
	if err != nil {
		fmt.Println("Login is err ", err)
	}
	defer tts.Logout()

	for i := 0; i < 1; i++ {
		fmt.Println(i)
		//tts.Logout()
		//tts.Login(fmt.Sprintf("appid = 603f4287, work_dir = %s", workDir))
		err := tts.GetTTSWavFile(params,
			"单次合成的文本"+strconv.Itoa(i),
			fmt.Sprintf("%s/%d.wav", path, i))
		if err != nil {
			panic(err)
		}
		//tts.Logout()
	}

	fmt.Println("app elapsed:", time.Since(tipTime).Milliseconds())
}
